package com.zhixiang.core.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class DateGather
{
  public static String getDateTime1()
  {
    String strDate = new SimpleDateFormat("yyyy-MM-dd")
      .format(new java.util.Date());
    return strDate;
  }

  public static String getDateTime2()
  {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String strDate = sdf.format(new java.util.Date());
    return strDate;
  }

  public static String getDateTime3()
  {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    String strDate = sdf.format(new java.util.Date());
    return strDate;
  }

  public static String getDateTime4()
  {
    Timestamp datetime = new Timestamp(Calendar.getInstance()
      .getTimeInMillis());
    return datetime.toString();
  }

  public static String getDateTime5()
  {
    String strDate = new SimpleDateFormat("yyyy年MM月dd日")
      .format(new java.util.Date());
    return strDate;
  }

  public static String getDateTime6()
  {
    String strDate = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss")
      .format(new java.util.Date());
    return strDate;
  }

  public static String getDateTime7()
  {
    String strDate = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒")
      .format(new java.util.Date());
    return strDate;
  }

  public static String getDateTime8()
  {
    String strDate = new SimpleDateFormat(
      "yyyy年MM月dd日 E HH:mm:ss").format(new java.util.Date());
    return strDate;
  }

  public static String getDateTime9()
  {
    String strDate = new SimpleDateFormat(
      "yyyy年MM月dd日 E HH时mm分ss秒").format(new java.util.Date());
    return strDate;
  }

  public static String getDateTime10()
  {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
    String strDate = sdf.format(new java.util.Date());
    return strDate;
  }

  public static java.sql.Date getDateTime11()
  {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.util.Date opertime = null;
    try {
      opertime = simpleDateFormat.parse(getDateTime2());
    }
    catch (ParseException e) {
      e.printStackTrace();
    }
    java.sql.Date sqldate = new java.sql.Date(opertime.getTime());
    return sqldate;
  }

  public static String getDateTime12()
  {
//    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
    String strKey = "lei**r**&Cs**L*h*D*y";
//    String strDate = sdf.format(new java.util.Date());
    return strKey;
  }

  public static java.util.Date getFirstDayOfMonth1(int year, int month)
  {
    Calendar cal = Calendar.getInstance();

    cal.set(1, year);

    cal.set(2, month - 1);

    cal.set(5, 1);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String firstDayOfMonth = sdf.format(cal.getTime());
    StringBuffer str = new StringBuffer().append(firstDayOfMonth).append(" 00:00:00");
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.util.Date firstDate = null;
    try {
      firstDate = simpleDateFormat.parse(str.toString());
    }
    catch (ParseException e) {
      e.printStackTrace();
    }

    return firstDate;
  }

  public static java.util.Date getFirstDayOfMonth2(int year, int month)
  {
    Calendar cal = Calendar.getInstance();

    cal.set(1, year);

    cal.set(2, month - 1);

    cal.set(5, 1);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String firstDayOfMonth = sdf.format(cal.getTime());
    java.util.Date firstDate = null;
    try {
      firstDate = sdf.parse(firstDayOfMonth);
    }
    catch (ParseException e) {
      e.printStackTrace();
    }

    return firstDate;
  }

  public static String getFirstDayOfMonth3(int year, int month)
  {
    Calendar cal = Calendar.getInstance();

    cal.set(1, year);

    cal.set(2, month - 1);

    cal.set(5, 1);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String firstDayOfMonth = sdf.format(cal.getTime());
    StringBuffer str = new StringBuffer().append(firstDayOfMonth).append(" 00:00:00");
    return str.toString();
  }

  public static String getFirstDayOfMonth4(int year, int month)
  {
    Calendar cal = Calendar.getInstance();

    cal.set(1, year);

    cal.set(2, month - 1);

    cal.set(5, 1);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String firstDayOfMonth = sdf.format(cal.getTime());
    return firstDayOfMonth;
  }

  public static java.util.Date getLastDayOfMonth1(int year, int month)
  {
    Calendar cal = Calendar.getInstance();

    cal.set(1, year);

    cal.set(2, month - 1);

    int lastDay = cal.getActualMaximum(5);

    cal.set(5, lastDay);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String lastDayOfMonth = sdf.format(cal.getTime());
    StringBuffer str = new StringBuffer().append(lastDayOfMonth).append(" 23:59:59");
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.util.Date lastDate = null;
    try {
      lastDate = simpleDateFormat.parse(str.toString());
    }
    catch (ParseException e) {
      e.printStackTrace();
    }

    return lastDate;
  }

  public static java.util.Date getLastDayOfMonth2(int year, int month)
  {
    Calendar cal = Calendar.getInstance();

    cal.set(1, year);

    cal.set(2, month - 1);

    int lastDay = cal.getActualMaximum(5);

    cal.set(5, lastDay);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String lastDayOfMonth = sdf.format(cal.getTime());
    java.util.Date lastDate = null;
    try {
      lastDate = sdf.parse(lastDayOfMonth);
    }
    catch (ParseException e) {
      e.printStackTrace();
    }
    return lastDate;
  }

  public static String getLastDayOfMonth3(int year, int month)
  {
    Calendar cal = Calendar.getInstance();

    cal.set(1, year);

    cal.set(2, month - 1);

    int lastDay = cal.getActualMaximum(5);

    cal.set(5, lastDay);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String lastDayOfMonth = sdf.format(cal.getTime());
    StringBuffer str = new StringBuffer().append(lastDayOfMonth).append(" 23:59:59");
    return str.toString();
  }

  public static String getLastDayOfMonth4(int year, int month)
  {
    Calendar cal = Calendar.getInstance();

    cal.set(1, year);

    cal.set(2, month - 1);

    int lastDay = cal.getActualMaximum(5);

    cal.set(5, lastDay);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String lastDayOfMonth = sdf.format(cal.getTime());

    return lastDayOfMonth;
  }

  public static int getDayOfYearMonth(int year, int month)
  {
    Calendar cal = Calendar.getInstance();

    cal.set(1, year);

    cal.set(2, month - 1);

    int lastDay = cal.getActualMaximum(5);
    return lastDay;
  }

  public static String getDateTime13(int year, int month, int day)
  {
    Calendar cal = Calendar.getInstance();

    cal.set(1, year);

    cal.set(2, month - 1);

    cal.set(5, day);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String dayOfMonth = sdf.format(cal.getTime());

    return dayOfMonth;
  }

  public static void main(String[] args)
  {
//    DateGather myDate = new DateGather();
    System.out.println(getDateTime1());
    System.out.println(getDateTime2());
    System.out.println(getDateTime3());
    System.out.println(getDateTime4());
    System.out.println(getDateTime5());
    System.out.println(getDateTime6());
    System.out.println(getDateTime7());
    System.out.println(getDateTime8());
    System.out.println(getDateTime9());
    System.out.println(getDateTime10());
    System.out.println("11:  " + getDateTime11());
    System.out.println("年月firstDay:" + getFirstDayOfMonth1(2015, 3));
    System.out.println("年月firstDay:" + getFirstDayOfMonth2(2015, 3));
    System.out.println("年月firstDay:" + getFirstDayOfMonth3(2015, 3));
    System.out.println("年月firstDay:" + getFirstDayOfMonth4(2015, 3));

    System.out.println("年月lastDay:" + getLastDayOfMonth1(2015, 3));
    System.out.println("年月lastDay:" + getLastDayOfMonth2(2015, 3));
    System.out.println("年月lastDay:" + getLastDayOfMonth3(2015, 3));
    System.out.println("年月lastDay:" + getLastDayOfMonth4(2015, 3));

    System.out.println("Day:" + getDayOfYearMonth(2015, 3));
    System.out.println("nowDay:" + getDateTime13(2015, 3, 6));
  }
}

